import { App } from 'vue'
export const regInteger = (app: App<Element>) => {
	app.directive('integer', {
		mounted(el) {
		  el.addEventListener('input', (event) => {
			const input = event.target as HTMLInputElement
			let value = input.value
			const regex = /^\d+$/ // 正则表达式，只匹配一个或多个数字
			if (!regex.test(value)) {
			  value = value.replace(/\D/g, '') // 过滤掉非数字字符
			}
			if(value === ''){
				input.value = 0
			}else{
				input.value = parseInt(value).toString() // 转换为数字并移除前导零
			}
		  })
		},
	})
}
